/**
 * Created by guosc on 2016/10/25 0025.
 */
define(["angular",
    "framework/utils/JSONPrettyFormat",
    'framework/dataGrid/DataGridModule',
    'framework/pagination/GillionPaginationModule',
    'framework/msg/GillionMsgModule'
],function (angular, JSONPrettyFormat) {
    var CopyPackageModule = angular.module("CopyPackageModule", [
        'DataGridModule',
        'GillionPaginationModule',
        'GillionMsgModule']);
    CopyPackageModule.controller("CopyPackageController", function ($scope,Resource,$location,GillionMsg,GillionMsgService,$http) {
        var app = Resource("/grule-manager/rulePackage/copy");
        $scope.project=GillionMsgService.getInputData();
        $http.get('/grule-manager/projects/allList').success(function (resp) {
            if(resp.data=="reload"){
                location.reload();
            }else {
                $scope.projects = resp.projects;
            }
        });

        $scope.setPackage=function(id){
            $http.get('/grule-manager/rulePackage/getRulePackages/' +id).success(function (resp) {
                if(resp.data=="reload"){
                    location.reload();
                }else {
                    $scope.packages = resp.data;
                }
            });
        };

        $scope.confirm=function(){
            $scope.rulePackage.projectid = $scope.project.projectId;
            app.create($scope.rulePackage,function(response){
                if (response.success) {
                    GillionMsgService.setOutputData(response);
                    GillionMsgService.close();
                } else {
                    GillionMsg.alert("提示", "规则复制失败");
                }
            })
        };
        $scope.cancel=function(){
            GillionMsgService.close();
        }

    });

});